package com.linzelin.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class ModelTest {

    @RequestMapping("/m/t/")
    public String test(Model model,@RequestParam("username") String name){
        model.addAttribute("msg",name);
        return "test";
    }

    @RequestMapping("/m/t2")
    public void test2(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();
        System.out.println(session.getId());

        req.getSession().setAttribute("msg","使用request转发请求");

        //使用rep来跳转
        req.getRequestDispatcher("/WEB-INF/jsp/test.jsp").forward(req,resp);
    }

   /* @RequestMapping("/m/t3")
    public void test3(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();
        System.out.println(session.getId());

        req.getSession().setAttribute("msg","使用response转发请求");

        //使用resp来跳转
        resp.sendRedirect("/WEB-INF/jsp/test.jsp");
    }*/
}
